<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">

          <a-col :md="6" :sm="8">
            <a-form-item label="商户名称">
              <a-select
                showSearch
                :value="value"
                placeholder="请输入商户名称"
                :defaultActiveFirstOption="false"
                :showArrow="false"
                :filterOption="false"
                @search="handleSearch"
                @change="handleChange"
                :notFoundContent="null"
                v-model="queryParam.sellerId"
              >
                <a-select-option  value="">请选择商户名</a-select-option>
                <a-select-option v-for="d in data" :key="d.value">{{d.text}}</a-select-option>
              </a-select>

            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('提现信息表')">导出</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
              <a @click="handleDetails(record.id)">提现</a>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <seller-cashInfo-details ref="details" ></seller-cashInfo-details>
  </a-card>
</template>

<script>
  import SellerCashInfoDetails from './modules/SellerCashInfoDetails'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import querystring from 'querystring';
  import { postAction,getAction } from '@/api/manage'

  let timeout;
  let currentValue;

  function fetch(value, callback) {
    if (timeout) {
      clearTimeout(timeout);
      timeout = null;
    }
    currentValue = value;

    function fake() {
      const str = querystring.encode({
        code: 'utf-8',
        q: value,
      });
      getAction(`/seller/web/list?username${str}`)
        .then(d => {
          if (currentValue === value) {
            const result = d.result.records;
            const data = [];
            result.forEach(r => {
              data.push({
                value: r.id,
                text: r.username,
              });
            });
            callback(data);
          }
        });
    }

    timeout = setTimeout(fake, 300);
  }

  export default {
    name: "SellerCashInfoList",
    mixins:[JeecgListMixin],
    components: {
      SellerCashInfoDetails
    },
    data () {
      return {
        availableCash:{},
        data: [],
        value: "",
        description: '提现管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
           },
		   {
            title: '商户名称',
            align:"center",
            dataIndex: 'username'
           },
		   {
            title: '商户手机号',
            align:"center",
            dataIndex: 'mobile'
           },
		   {
            title: '已提现金额',
            align:"center",
            dataIndex: 'hasCash',
         customRender: text => {
           if(text == null || text == 0){
             return 0
           }else {
             return text  / 100
           }
         }
           },
		   {
            title: '待提现金额',
            align:"center",
            dataIndex: 'availableCash',
         customRender: text => {
           this.availableCash = text == null?0:text/100
           if(text == null || text == 0){
             return 0
           }else {
             return text  / 100
           }
         }
           },
		   {
            title: '提现中金额',
            align:"center",
            dataIndex: 'cashingMoney',
           customRender: text => {
              if(text == null || text == 0){
                return 0
              }else {
                return text  / 100
              }
           }
           },
		   // {
       //      title: '是否删除',
       //      align:"center",
       //      dataIndex: 'deleted'
       //     },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
		url: {
          list: "/cashInfoLog/merchant/getSellersCashInfo",
          delete: "/crash/delete",
          deleteBatch: "/crash/deleteBatch",
          exportXlsUrl: "cashInfoLog/exportXls",
          importExcelUrl: "crash/importExcel",
       },
    }
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
    methods: {
      handleSearch(value) {
        fetch(value, data => (this.data = data));
      },
      handleChange(value) {
        console.log(value);
        this.value = value;
        fetch(value, data => (this.data = data));
      },
      handleDetails(id) {
        // if (this.availableCash > 0){
            this.$refs.details.show(id)
        // }
        // this.$notification.success({
        //   message: '系统通知',
        //   description: `注意 : `+"提现金额必须大于 0 元",
        // });

      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>